<?php
class Pfg{
	public $site_id = 0;
	//构造函数
	public function Pfg($site_id = 0){
		if($site_id == 0){
			$site_id = defined('__ADMINSITEID__')?__ADMINSITEID__:__SITEID__;
		}
		
		$this->site_id = $site_id;
		
	
	}
	//创建设置项表单
	public function createform(){
		
		
	}
	
	//保存设置项
	public function saveform(){
		
	}
	
	//发起支付
	public function pay($orderid){
		$ordermes = M('Order')->where(array('id'=>$orderid, 'site_id' => $this->site_id))->find();
		$Setbody = $ordermes['ordernumber'].$ordermes['id'];
		$SetTotal_fee = $ordermes['total'];
		$flmdb = M('Agentflmlevel');
		$member = $m = $flmdb -> where(array('site_id', $this->site_id, 'member_id' => $ordermes['member_id'])) -> order('id desc') -> find();
		//余额是否足够
		if($member['money'] >= $SetTotal_fee){
			$ret = D('Order') -> upstate($ordermes['ordernumber']);
			if($ret){
				if($m){
					//存在最新记录
					unset($m['id']);
					//把金额加上去
					$m['money'] -= $ordermes['total']*1;
					$m['lastchange'] = $ordermes['total']*1;
					$m['dateline'] = time();
					$m['remark'] = '支付订单'.$ordermes['ordernumber'];
					$r = $flmdb -> add($m);
				}
				$html = '<script>setTimeout(function(){$("#payPro").html("支付成功");
				$("#payend").show();},500);</script>';
			}
		}else{
			$html = '<script>alert(\'支付失败！货款余额不足！\');</script>';
		}
		 
		return $html;
	}
	public function callback(){
	}
	
}

	

